const router = require("koa-router")();

router.prefix("/che");

const PagerHelper = require("./PagerHelper");




router.get("/list", async (ctx, next) => {
  var sql = `SELECT * FROM plat_employee LIMIT 0,10`;
  var result = await PagerHelper.getQueryResult(sql, null);
  ctx.body = PagerHelper.SuccessRes(result);
});

router.post("/list", async (ctx, next) => {
  const { category_type, search_key, pager } = ctx.request.body;

  var sql = `select
                *
                FROM plat_employee
                WHERE 
                1=1 `;

  // if (!PagerHelper.StringIsNullOrEmpty(category_type)) {
  //     sql += `and category_type=${category_type}`
  // }

  // if (!PagerHelper.StringIsNullOrEmpty(search_key)) {
  //     sql += `and (title=${search_key} || title=${search_key} || id=${search_key} )`
  // }

  var result = await PagerHelper.getQueryResult(sql, pager);

  ctx.body = PagerHelper.SuccessRes(result);
});

module.exports = router;
